package com.service.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.mybatis.generator.codegen.ibatis2.sqlmap.elements.SelectByPrimaryKeyElementGenerator;

import com.dao.GradeMapper;
import com.entity.Grade;
import com.service.GradeService;
import com.util.MyBatisUtil;

public class GradeServiceImpl implements GradeService {

	// 查询所有班级
	@Override
	public List<Grade> selectAllGrade() {
		SqlSession sqlSession = MyBatisUtil.getSession();
		GradeMapper gm = sqlSession.getMapper(GradeMapper.class);
		List<Grade> list = gm.selectAllGrade();
		MyBatisUtil.closeSession();
		return list;
	}

	// 查询单个班级
	@Override
	public Grade selectByPrimaryKey(Integer gid) {
		SqlSession sqlSession = MyBatisUtil.getSession();
		GradeMapper gm = sqlSession.getMapper(GradeMapper.class);
		Grade grade = gm.selectByPrimaryKey(gid);
		MyBatisUtil.closeSession();
		return grade;
	}

	// 删除班级（按编号删除）
	@Override
	public int deleteByPrimaryKey(Integer gid) {
		SqlSession sqlSession = MyBatisUtil.getSession();
		GradeMapper gm = sqlSession.getMapper(GradeMapper.class);
		int temp = gm.deleteByPrimaryKey(gid);
		sqlSession.commit();
		MyBatisUtil.closeSession();
		return temp;
	}

	// 修改班级
	@Override
	public int updateByPrimaryKey(Grade grade) {
		SqlSession sqlSession = MyBatisUtil.getSession();
		GradeMapper gm = sqlSession.getMapper(GradeMapper.class);
		int temp = gm.updateByPrimaryKey(grade);
		sqlSession.commit();
		MyBatisUtil.closeSession();
		return temp;
	}

	// 多表查询
	@Override
	public List<Grade> selectGradeStudent() {
		SqlSession sqlSession = MyBatisUtil.getSession();
		GradeMapper gm = sqlSession.getMapper(GradeMapper.class);
		List<Grade> list = gm.selectGradeStudent();
		MyBatisUtil.closeSession();
		return list;
	}

}
